Nengo Tutorial

Nengo

  • Our neural simulator
  • Implements the basics of what we cover in this class

    • So you don't have to worry about the implementation details
    • But understanding the theory will help you use it better
  • website: Nengo.ca

  • install: Download Nengo
    • use the "latest development version of Nengo"
    • Java application; runs on Linux, OS X, Windows
    • Open Source: Github repository

How to use it


In [ ]:
import nef
net = nef.Network('Example')
net.make_input('input', [0])

net.make('A', neurons=75, dimensions=1)
net.make('B', neurons=50, dimensions=1)

def square(x):
    return x[0]*x[0]

net.connect('A', 'B', func=square)

net.connect('input', 'A')

net.add_to_nengo()
  • More advanced usage

The creature we made in class

  • Should set motor to be the direction we tell it to go in with command, unless scared is 1, in which can it should try to go back to position (0,0)

In [ ]:
import nef

net = nef.Network('Creature')

net.make_input('command_input', [0,0])

net.make('command', neurons=100, dimensions=2)

net.make('motor', neurons=100, dimensions=2)

net.make('position', neurons=1000, dimensions=2, radius=5)

net.make('scared_direction', neurons=100, dimensions=2)

def negative(x):
    return -x[0], -x[1]

net.connect('position', 'scared_direction', func=negative)

net.connect('position', 'position')

net.make('plan', neurons=500, dimensions=5)
net.connect('command', 'plan', index_post=[0,1])
net.connect('scared_direction', 'plan', index_post=[2,3])
net.make('scared', neurons=50, dimensions=1)
net.make_input('scared_input', [0])
net.connect('scared_input', 'scared')
net.connect('scared', 'plan', index_post=[4])

def plan_function(x):
    c_x, c_y, s_x, s_y, s = x
    return s*(s_x)+(1-s)*c_x, s*(s_y)+(1-s)*c_y
    
net.connect('plan', 'motor', func=plan_function)    


def rescale(x):
    return x[0]*0.1, x[1]*0.1

net.connect('motor', 'position', func=rescale)


net.connect('command_input', 'command')

net.add_to_nengo()